package cn.sc.allinpay.allfavour.business.common.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.business.common.dialog.CheckInputRemarkDialog;

/**
 * description：自定义备注视图
 * author：pany
 * on 2018/10/26 14:31
 */
public class CustomRemarkView extends FrameLayout implements View.OnClickListener {

    private AppCompatTextView tvName;
    private AppCompatTextView tvEdit;
    private AppCompatTextView tvDel;
    private String remark;
    private OnRemarkListener onRemarkListener;

    public CustomRemarkView(@NonNull Context context) {
        super(context);
        init();
    }

    public CustomRemarkView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.custom_remark_view, this);
        tvName = view.findViewById(R.id.tvName);
        tvName.setOnClickListener(this);
        tvEdit = view.findViewById(R.id.tvEdit);
        tvEdit.setOnClickListener(this);
        tvDel = view.findViewById(R.id.tvDel);
        tvDel.setOnClickListener(this);
    }

    private void showRemark() {
        if (tvName != null)
            tvName.setText(remark);
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
        showRemark();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tvName:
                CheckInputRemarkDialog dialog = new CheckInputRemarkDialog(getContext());
                dialog.setOnDialogListener(new CheckInputRemarkDialog.OnDialogListener() {
                    @Override
                    protected void onConfirm(String input) {
                        setRemark(input);
                    }
                });
                dialog.show();
                break;
            case R.id.tvEdit:
                break;
            case R.id.tvDel:
                onRemarkListener.onDelete(this);
                break;
        }
    }

    public void setOnRemarkListener(OnRemarkListener onRemarkListener) {
        this.onRemarkListener = onRemarkListener;
    }

    public interface OnRemarkListener {
        void onDelete(View view);
    }
}
